<template>
  <div>
    <el-table
    :data="cartData"
    border
    style="width: 100%"
    class="table">
    <el-table-column
      type="username"
      prop="username"
      label="用户名"
      width="100">
    </el-table-column>
    <el-table-column
      fixed
      prop="title"
      label="书籍名称"
      width="150">
    </el-table-column>
    <el-table-column
      prop="author"
      label="作者"
      width="120">
    </el-table-column>
    <el-table-column
      prop="category"
      label="分类"
      width="120">
    </el-table-column>
    <el-table-column
      prop="description"
      label="描述"
      width="120">
    </el-table-column>
    <el-table-column
      prop="publishDate"
      label="出版社"
      width="300">
    </el-table-column>
    <el-table-column
      prop="price"
      label="价格"
      width="120">
    </el-table-column>
    <el-table-column
      prop="quantity"
      label="数量"
      width="120">
    </el-table-column>
    <el-table-column
      prop="status"
      label="状态"
      width="120">
    </el-table-column>
    
    <el-table-column
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">修改状态</el-button>
      </template>
    </el-table-column>
    <el-table-column
      label="删除"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick1(scope.row)" type="text" size="small">删除订单</el-button>
      </template>
    </el-table-column>
  </el-table>
  
  </div>
</template>

<script>
import service from '@/axios/axiosConfig'
export default {
    data() {
        return {
            cartData: [],
          userData: [],
            total: "",
      pageNum: 1,
      pageSize: 100,
      totalPage: ""
        }
    },
    methods: {
        async handleClick(row){
            console.log(row.status)
            const responseBody={
                orderId: row.orderId,
                status: row.status == '待发货' ? '已发货':'待发货'
            }
            const response = await service.post('http://localhost:8080/order/updateOrder', responseBody)
            this.$message.success("修改成功")
            console.log(response)
            this.$router.go(0)
      },
    },
    async created() {
       
        
        const responseBody = {
            pageNum: this.pageNum,
            pageSize: this.pageSize
        }
        console.log(responseBody)
        const response = await service.post('http://localhost:8080/adminUser/getAllUsers',responseBody)
        this.userData = response.data.data.list
        console.log(response.data.data.list)
      this.total = response.data.data.total
        
        for (var i = 0; i < this.userData.length; i++){
            const responseBody1 = {
            username: this.userData[i].username,
            pageNum: this.pageNum,
            pageSize: this.pageSize
        }
        const response1 = await service.post('http://localhost:8080/order/queryOrders', responseBody1)
            console.log(response1.data.data.list)
        const ordersWithUsername = response1.data.data.list.map(order => ({
        ...order,
        username: this.userData[i].username
    }));
        this.cartData = this.cartData.concat(ordersWithUsername)
        }
         
    }
}
</script>